package sfeir.ergosum.tools;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MyThreadPoolExecutor {

    static MyThreadPoolExecutor instance;

    int poolSize = 2;

    int maxPoolSize = 2;

    long keepAliveTime = 10;

    ThreadPoolExecutor threadPool = null;

    final ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(
            500);

    public MyThreadPoolExecutor() {
        threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize,
                keepAliveTime, TimeUnit.SECONDS, queue);

    }

    public static MyThreadPoolExecutor getInstance() {
        if (null == instance) {
            instance = new MyThreadPoolExecutor();
        }
        return instance;
    }

    public void runTask(Runnable task) {
        threadPool.execute(task);

    }

    public void shutDown() {
        threadPool.shutdown();
    }
}
